package com.doublefish.doublefishrobot.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.doublefish.doublefishrobot.R;

/**
 * 作者:dugaofeng on 2024/10/16 11:02
 */
public class SharedPreferencesUtils {

    private SharedPreferences mSp;
    private static SharedPreferencesUtils sharedPreferencesUtils;
    private boolean didInitSharedPreferencesUtils = false;


    public static SharedPreferencesUtils getInstant(){
        if (sharedPreferencesUtils==null){
            synchronized (SharedPreferencesUtils.class){
                if (sharedPreferencesUtils==null){
                    sharedPreferencesUtils = new SharedPreferencesUtils();
                }
            }
        }
        return sharedPreferencesUtils;
    }

    // 在app开始的时候初始化
    public void init(Context context) {
        if (didInitSharedPreferencesUtils) {
            return;
        }
        mSp = context.getSharedPreferences(context.getString(R.string.app_name),Context.MODE_PRIVATE);
        didInitSharedPreferencesUtils = true;
    }

    public SharedPreferencesUtils() {

    }
    //是否阅读了隐私政策
    public boolean didReadPrivacy() {
        return mSp.getBoolean("didReadPrivacy", false);
    }

    public boolean setDidReadPrivacy(boolean didReadPrivacy) {
        return mSp.edit().putBoolean("didReadPrivacy", didReadPrivacy).commit();
    }


    //region 视频下载设置
    //0.仅WiFi  1.WiFi和移动网络
    public int getVideoDownloadType() {
        return mSp.getInt("hdVideoDownloadType", 0);
    }

    public boolean setVideoDownloadType(int videoDownloadType) {
        return mSp.edit().putInt("hdVideoDownloadType", videoDownloadType).commit();
    }
    //endregion


    //region 左右手设置 00左手，01右手 默认右手
    public int getHandTag() {
        return mSp.getInt("handTag", 1);
    }

    public boolean setHandTag(int handTag) {
        return mSp.edit().putInt("handTag", handTag).commit();
    }
    //endregion


    //region  超5的后台运行方案 默认0
    //超5的后台运行方案 默认0
    public int getBgProgram() {
        return mSp.getInt("s5BgProgram", 0);
    }

    public boolean setBgProgram(int bgProgram) {
        return mSp.edit().putInt("s5BgProgram", bgProgram).commit();
    }
    // 超5的后台运行方案 亮度
    public float getBgLight() {
        return mSp.getFloat("s5BgLight", 0.1f);
    }

    public boolean setBgLight(float bgLight) {
        return mSp.edit().putFloat("s5BgLight", bgLight).commit();
    }
    // 超5的后台运行方案 播放MP3
    public boolean isBgPlayer() {
        return mSp.getBoolean("s5BgPlayer", true);
    }

    public boolean setBgPlayer(boolean bgPlayer) {
        return mSp.edit().putBoolean("s5BgPlayer", bgPlayer).commit();
    }
    //endregion

    //设置是否在速度较快时  进行提示
    public boolean isIgnoreSpeedTips() {
        return mSp.getBoolean("ignoreSpeedTips", false);
    }

    public boolean setIgnoreSpeedTips(boolean ignoreSpeedTips) {
        return mSp.edit().putBoolean("ignoreSpeedTips", ignoreSpeedTips).commit();
    }


    //多语言设置
    public int getLanguageType() {
        return mSp.getInt("languageType", 0);
    }

    public boolean setLanguageType(int languageType) {
        return mSp.edit().putInt("languageType", languageType).commit();
    }

    public String getStringValue(String key, String defaultValue) {
        return mSp.getString(key, defaultValue);
    }

    public boolean setStringValue(String key, String value) {
        return mSp.edit().putString(key, value).commit();
    }
}
